<template>
	<view class="goods-detail" :style="{paddingBottom:120+bottomLift+'rpx'}">
		<form :borderBottom="false" @reset="formReset">
			<view class="uni-form-item uni-column" v-if="secondHand">
				<view class="select tabs">
					<view class="tabs_item" :class="!goodInfo.secondhand?'active':''" @click="changeType(false)">
						{{$t('goods.brandNew')}}
					</view>
					<view class="tabs_item" :class="goodInfo.secondhand?'active':''" @click="changeType(true)">
						{{$t('goods.secondHand')}}
					</view>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.commodityInternationalCode')}}<text class="required">*</text></view>
				<view class="select">
					<input class="uni-input" :placeholder="$t('goods.pleaseEnterTheProductInternationalCode')"
						v-model="goodInfo.keyword" @input="querySearchAsync" />
					<picker :value="index" @change="bindPickerKeyword" :range="keywordList" range-key="keyword"
						v-if="keywordList.length>0">
						<!-- <i class='iconfont iconarrow-right1'></i> -->
						<view class="keyBtn" v-if="keywordList.length>0">{{$t('goods.match')}}</view>
					</picker>
				</view>
				<!-- <input class="uni-input" placeholder="请输入商品国际编码" v-model="goodInfo.keyword" @input="querySearchAsync" v-else /> -->
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.commodityStatus')}}</view>
				<!--商品状态-->
				<u-switch v-model="goodInfo.isShow" size="40" active-color="#000000"></u-switch>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.productName')}}<text class="required">*</text></view>
				<input class="uni-input" name="input" v-model="goodInfo.storeName" @input="check_input"
					:placeholder="$t('goods.pleaseEnterProductName')" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.unit')}}<text class="required">*</text></view>
				<input class="uni-input" name="input" v-model="goodInfo.unitName" @input="check_input"
					:placeholder="$t('goods.pleaseEnterUnit')" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.brand')}}<text class="required">*</text></view>
				<picker @change="bindPickerBrand" :value="index" :range="brandList" range-key="enName">
					<view class="select">
						<input class="uni-input" name="input" :disabled="true" v-model="goodInfo.brandName"
							:placeholder="$t('goods.pleaseSelectBrand')" />
						<i class='iconfont iconarrow-right1'></i>
					</view>
				</picker>
			</view>
			<view class="uni-form-item uni-column" @click="showPicker = true">
				<view class="title">{{$t('goods.classification')}}<text class="required">*</text></view>
				<view class="select">
					<input class="uni-input" name="input" :disabled="true" v-model="goodInfo.cateName"
						:placeholder="$t('goods.pleaseSelectType')" />
					<i class='iconfont iconarrow-right1'></i>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.productMainImage')}}<text class="required">*</text></view>
				<view class="imageBox">
					<u-upload :action="action" ref='upload' :header="headers" @on-success="(res)=> uploadImg(res, 0)"
						@on-remove="(index)=>deletePic(index,0)" name="multipart" :max-count="1" :custom-btn="true"
						width="112" height="112" :show-progress="false" :file-list="fileListImg"
						style="overflow:auto !important;">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
						</view>
					</u-upload>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.productCarousel')}}<text class="required">*</text></view>
				<view class="imageBox">
					<u-upload :action="action" ref='upload1' :header="headers" name="multipart" :max-count="9"
						@on-success="(res)=> uploadImg(res, 1)" @on-remove="(index)=>deletePic(index,1)"
						:custom-btn="true" width="112" height="112" :show-progress="false"
						:file-list="fileListsliderImage">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
						</view>
					</u-upload>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title" v-if="!goodInfo.secondhand">{{$t('goods.productDetails')}}</view>
				<view class="title" v-else>{{$t('goods.blemishMap')}}<text class="required">*</text></view>
				<view class="imageBox">
					<u-upload :action="action" ref='upload5' :header="headers" name="multipart" :max-count="9"
						@on-success="(res)=> uploadImg(res, 5)" @on-remove="(index)=>deletePic(index,5)"
						:custom-btn="true" width="112" height="112" :show-progress="false"
						:file-list="fileListproductDetails">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
						</view>
					</u-upload>
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.productDescription')}}</view>
				<textarea class="text" :placeholder="$t('goods.productDescriptionPlaceholder')" @input="check_input"
					v-model="goodInfo.storeInfo" />
			</view>
			<view class="uni-form-item uni-column" v-if="goodInfo.secondhand">
				<view class="title">{{$t('goods.newOrOld')}}<text class="required">*</text></view>
				<input class="uni-input" name="input" v-model="goodInfo.degree"
					:placeholder="$t('goods.pleaseEnterTheDegreeOfOldOrNew')" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">{{$t('goods.productDetails')}}</view>
				<view class="goodsInfo">
					<view class="item-list">
						<view class="item" v-for="(item,index) in informationList" :key="index">
							<label class="title1">{{item.productInformation}}</label>
							<input type="text" v-model="item.value" :placeholder="$t('publicLang.pleaseEnter')">
						</view>
						<view class="item" v-if="showField.seasonCode">
							<label class="title1">{{$t('goods.season')}}</label>
							<picker class="picker" @change="bindPickerSeason" :value="index" :range="seasonList"
								range-key="name">
								<view class="select" style="background:#ffffff">
									<input type="text" v-model="goodInfo.seasonCode"
										:placeholder="$t('publicLang.pleaseChoose')" disabled="disabled">
									<i class='iconfont iconarrow-right1'></i>
								</view>
							</picker>
						</view>
						<view class="item" v-if="showField.composition">
							<label class="title1">{{$t('goods.element')}}</label>
							<input type="text" v-model="goodInfo.composition" :placeholder="$t('publicLang.pleaseEnter')">
						</view>
						<view class="item" v-if="showField.dimension">
							<label class="title1">{{$t('goods.specification')}}</label>
							<input type="text" v-model="goodInfo.dimension" :placeholder="$t('publicLang.pleaseEnter')">
						</view>
						<view class="item" v-if="showField.colorCode">
							<label class="title1">{{$t('goods.color')}}</label>
							<input type="text" v-model="goodInfo.colorCode" :placeholder="$t('publicLang.pleaseEnter')">
						</view>
						<view class="item" v-if="showField.productionPlace">
							<label class="title1">{{$t('goods.origin')}}</label>
							<input type="text" v-model="goodInfo.productionPlace" :placeholder="$t('goods.pleaseEnterTheCountryOfOrigin')">
						</view>
						<view class="item" v-if="showField.weight">
							<label class="title1">{{$t('goods.weight')}}</label>
							<input type="number" v-model="goodInfo.weight" :placeholder="$t('goods.pleaseEnterWeight')">(kg)
						</view>
					</view>
				</view>
			</view>
			<view>
				<view class="uni-form-item uni-column">
					<view class="title">{{$t('goods.placeOfShipment')}} <text class="required">*</text></view>
					<view class="select" @click="handleTap('stockAreaPicker')">
						<input class="uni-input" name="input" :disabled="true" v-model="goodInfo.tempName"
							:placeholder="$t('goods.pleaseSelectTheShippingLocation')" />
						<i class='iconfont iconarrow-right1'></i>
					</view>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">{{$t('goods.estimatedDeliveryTime')}}<text class="required">*</text></view>
					<view class="time">
						<input name="input" type="number" v-model="goodInfo.deliveryData"
							:placeholder="$t('goods.pleaseEnterDeliveryTime')" style="width:100%" />
						<text>{{$t('goods.day')}}</text>
					</view>

				</view>
				<view class="uni-form-item uni-column">
					<view class="title">{{$t('goods.expectedArrivalTime')}}<text class="required">*</text></view>
					<view class="time">
						<input type="number" v-model="goodInfo.earliestArrivalData" name="input" />{{$t('goods.day')}}
						<text style="display: inline-block;padding: 0rpx 60rpx;">{{$t('goods.to')}}</text>
						<input type="number" v-model="goodInfo.slowestArrivalData" name="input"
							style="text-align: center;" />{{$t('goods.day')}}
					</view>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">{{$t('goods.productRecommendationMap')}}</view>
					<view class="imageBox">
						<!-- <image class="image" v-if="goodInfo.recommendImg" :src="item.recommendImg"></image>
            <image class="image" src="../../static/images/add.png" v-else></image> -->
						<u-upload :action="action" :header="headers" name="multipart"
							@on-success="(res)=> uploadImg(res, 2)" @on-remove="(index)=>deletePic(index,2)"
							:max-count="1" ref='upload2' :custom-btn="true" width="112" height="112"
							:show-progress="false" :file-list="fileListrecommendImg">
							<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
								<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
							</view>
						</u-upload>
					</view>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">{{$t('goods.productVideo')}}</view>
					<view class="imageBox">
						<upload-video :value="goodInfo.videoLink" :key="goodInfo.videoLink" @videoUrl="getVideoUrl">
						</upload-video>
					</view>
				</view>
				<view class="uni-form-item uni-column">
					<block>
						<view class="title" v-if="!id || goodInfo.specType==1">{{$t('goods.addProductSpecifications')}}
						</view>
						<view v-if="!id">
							<u-radio-group width="50%" v-model="goodInfo.specType">
								<u-radio name="0">{{$t('goods.singleSpecification')}}</u-radio>
								<u-radio name="1">{{$t('goods.multipleSpecifications')}}</u-radio>
							</u-radio-group>
						</view>
					</block>
					<block v-if="goodInfo.specType==0">
						<view class="goodsInfo1">
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.specificationDrawing')}}</label>
									<view class="imageBox">
										<!-- <image class="image" src="../../static/images/add.png"></image> -->
										<u-upload ref="imageRef" :action="action" :header="headers" :max-count="1"
											@on-success="(res)=> uploadImg(res, 3)"
											@on-remove="(index)=>deletePic(index,3)" name="multipart" :custom-btn="true"
											width="112" height="112" :show-progress="false"
											:file-list="OneattrValue[0].imageurl">
											<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover"
												hover-stay-time="150">
												<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
											</view>
										</u-upload>
									</view>
								</view>
							</view>
							<!-- <view class="item-list">
                <view class="item">
                  <label class="title1">颜色</label>
                  <input type="text" placeholder="请输入">
                </view>
                <view class="item" style="border-left:1rpx solid #E8E9ED">
                  <label class="title1">尺寸</label>
                  <input type="text" placeholder="请输入">
                </view>
              </view> -->
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.sellingPrice')}}(￥)</label>
									<input type="number" v-model="OneattrValue[0].price">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.supplyPrice')}}(￥)</label>
									<input type="number" v-model="OneattrValue[0].cost">
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.originalPrice')}}(€)</label>
									<input type="digit" v-model="OneattrValue[0].otPrice">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.inStock')}}</label>
									<input type="number" v-model="OneattrValue[0].stock">
								</view>
							</view>
						</view>
					</block>
					<block v-else>
						<view style="padding: 20rpx 0;">
							<input class="uni-input" name="input" @click="handleTap('selectRulePicker')" disabled
								v-model="goodInfo.selectRuleName"
								:placeholder="$t('goods.pleaseSelectASpecification')" />
						</view>
						<view class="selectRuleList">
							<block v-for="(item,index) in goodInfo.attr" :key="index">
								<view class="selectRuleItem" v-for="(iitem,iindex) in item.attrValue" :key="iindex">
									{{iitem}}
									<u-icon class="icon" name='close' @click="handleClose(item.attrValue,indexn)">
									</u-icon>
								</view>
								<block v-if="goodInfo.specType==1">
									<view class="selectRuleAddItem" v-if="!editState" @click="addAttr()">
										<u-icon name='plus'></u-icon> {{$t('goods.addTo')}}
									</view>
									<view class="selectRuleAddItem" v-if="editState"><input
											v-model="item.attrValue.attrsVal" :focus="editState"
											:placeholder="$t('publicLang.pleaseEnter')"
											@blur="addAttrBlur(item.attrValue.attrsVal,index)" /></view>
								</block>
							</block>
						</view>
					</block>
					<block v-if="goodInfo.attr.length>0&&goodInfo.specType==1">
						<view class="goodsInfo1">
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.specificationDrawing')}}</label>
									<view class="imageBox">
										<!-- <image class="image" src="../../static/images/add.png"></image> -->
										<u-upload :action="action" :header="headers"
											@on-success="(res)=> uploadImg(res, 3)"
											@on-remove="(index)=>deletePic(index,3)" :max-count="1" name="multipart"
											:custom-btn="true" width="112" height="112" :show-progress="false"
											:file-list="batchImage">
											<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover"
												hover-stay-time="150">
												<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
											</view>
										</u-upload>
									</view>
								</view>
								<view class="item">
									<view class="btn" @click="batchAdd">{{$t('goods.bulkAdd')}}</view>
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.sellingPrice')}}(￥)</label>
									<input type="number" v-model="OneattrValue.price">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.supplyPrice')}}(￥)</label>
									<input type="number" v-model="OneattrValue.cost">
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.originalPrice')}}(€)</label>
									<input type="number" v-model="OneattrValue.otPrice">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.inStock')}}</label>
									<input type="number" v-model="OneattrValue.stock" placeholder="0">
								</view>
							</view>
						</view>
						<view class="goodsInfo1" v-for="(iitem,index1) in ManyAttrValue" :key="index1">
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.specificationDrawing')}}</label>
									<view class="imageBox">
										<!-- <image class="image" src="../../static/images/add.png"></image> -->
										<u-upload :action="action" :header="headers" :max-count="1"
											@on-success="(res)=> uploadImg(res, 4,index1)" ref='upload4'
											@on-remove="(index)=>deletePic(index,4,index1)" name="multipart"
											:custom-btn="true" width="112" height="112" :show-progress="false"
											:file-list="iitem.imageurl">
											<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover"
												hover-stay-time="150">
												<u-icon name="plus" size="48" color="#c0c4cc"></u-icon>
											</view>
										</u-upload>
									</view>
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{goodInfo.attr[0].attrName}}</label>
									<view style="flex: 1;">{{iitem.manyTabDate}}</view>
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.sellingPrice')}}(￥)</label>
									<input type="number" v-model="iitem.price">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.supplyPrice')}}(￥)</label>
									<input type="number" v-model="iitem.cost">
								</view>
							</view>
							<view class="item-list">
								<view class="item">
									<label class="title1">{{$t('goods.originalPrice')}}(€)</label>
									<input type="number" v-model="iitem.otPrice">
								</view>
								<view class="item" style="border-left:1rpx solid #E8E9ED">
									<label class="title1">{{$t('goods.inStock')}}</label>
									<input type="number" :min="0" v-model="iitem.stock">
								</view>
							</view>
						</view>
					</block>
				</view>
			</view>
		</form>
		<view class="address_mask back_mask" @click="showPicker = false" v-if="showPicker">
			<view class="picker_address_box pos_absolute1" @click.stop>
				<view class="picker_btn flex3">
					<view class="btn_cancle" @click="showPicker = false">{{$t('publicLang.cancel')}}</view>
					<view class="btn_confirm" @click="confirmTap">{{$t('publicLang.sure')}}</view>
				</view>
				<view class="picker_box">
					<view class="hk_mac">
						<picker-view v-if="productList.length > 0" class="picker_view" @change="bindChange2"
							:value="value2">
							<picker-view-column class="area_type">
								<view class="item flex1" v-for="(item,index) in productList" :key="index">{{item.name}}
								</view>
							</picker-view-column>
							<picker-view-column class="area_city">
								<view class="item flex1" v-for="(item,index) in productList[index1]['child']"
									:key="index">{{item.name}}</view>
							</picker-view-column>
							<picker-view-column class="area_city">
								<view class="item flex1"
									v-for="(item,index) in productList[index1]['child'][index2]['child']" :key="index">
									{{item.name}}
								</view>
							</picker-view-column>
						</picker-view>
					</view>
				</view>
			</view>
		</view>
		<view class="footer" :class="bottomLift!=0?'bottomLift':''" :style="{paddingBottom: `${bottomLift}rpx`}">
			<view class="btn" @click="handleSubmit">{{$t('goods.submit')}}</view>
		</view>
		<lb-picker ref="stockAreaPicker" v-model="goodInfo.tempId" mode="selector"
			:dataset="{ name: 'stockAreaPicker' }" :cancel-text="$t('publicLang.cancel')"
			:confirm-text="$t('publicLang.sure')" :list="stockArea" @confirm="handleConfirm">
		</lb-picker>
		<lb-picker ref="selectRulePicker" v-model="goodInfo.selectRule" mode="selector"
			:dataset="{ name: 'selectRulePicker' }" :cancel-text="$t('publicLang.cancel')"
			:confirm-text="$t('publicLang.sure')" :list="ruleList" @confirm="handleConfirm">
		</lb-picker>
	</view>
</template>
<script>
	let app = getApp();
	import {
		mapGetters
	} from "vuex";
	import {
		HTTP_REQUEST_URL,
		TOKENNAME
	} from "@/config/app";
	import {
		insideProductDetailApi,
		productResetPrice,
		productNormKeywordApi,
		brandList,
		seasonListMer,
		stockAreaList,
		templateListApi,
		productCreateApi,
		productUpdateApi,
		getRuleByCate
	} from "@/api/storeGoods.js";
	import uploadVideo from '@/components/uploadVideo/upload-video.vue'
	import {
		categoryApi
	} from "@/api/store.js";
	const defaultObj = {
		secondhand: false,
		degree: '',
		productionPlace: '',
		detailImages: [],
		sp1: "",
		weight: '',
		videoLink: '',
		image: "",
		recommendImg: "",
		sliderImages: [],
		sliderImage: "",
		storeName: "",
		storeInfo: "",
		keyword: "",
		brandId: "",
		brandName: "",
		cateIds: "", // 商品分类id
		cateId: null, // 商品分类id传值
		unitName: "",
		sort: 0,
		giveIntegral: 0,
		ficti: 0,
		isShow: true,
		isBenefit: false,
		isNew: false,
		isGood: false,
		isHot: false,
		isBest: false,
		tempId: "",
		attrValue: [{
			image: "",
			price: 0,
			cost: 0,
			otPrice: 0,
			stock: 0,
			// barCode: '',
			// weight: 0,
			// volume: 0
		}, ],
		attr: [],
		selectRule: "",
		isSub: false,
		content: " ",
		specType: 1,
		id: 0,
		couponIds: [],
		coupons: [],
		composition: "",
		dimension: "",
		deliveryData: "",
		slowestArrivalData: "",
		earliestArrivalData: ""
	};
	export default {
		computed: mapGetters(["token", "secondHand"]),
		data() {
			return {
				id: "",
				goodInfo: Object.assign({}, defaultObj),
				//   ManyAttrValue: [], // 存储商品多规格数据列表
				manyTabTit: [],
				OneattrValue: [Object.assign({}, defaultObj.attrValue[0])], // 单规格
				ManyAttrValue: [Object.assign({}, defaultObj.attrValue[0])], // 多规格
				list: ['全新', '二手'],
				detailData: [],
				productList: [],
				keywordList: [],
				brandList: [],
				seasonList: [],
				showPicker: false,
				index1: 0,
				index2: 0,
				value2: [0, 0, 0],
				stockArea: [], //发货地列表
				ruleList: [], //规格列表
				action: "",
				headers: "",
				fileListImg: [],
				fileListsliderImage: [],
				fileListrecommendImg: [],
				fileListproductDetails: [],
				editState: false,
				bottomLift: app.globalData.bottomLift,
				showkey: false,
				batchImage: [],
				// attrInfo: {},
				informationList: [],
				showField: {
					composition: false,
					dimension: false,
					seasonCode: false,
					colorCode: false,
					productionPlace: false,
					weight: false,
				}
			};
		},
		components: {
			uploadVideo
		},
		// watch: {
		//   "goodInfo.attr": {
		//     handler: function (val) {
		//       if (this.goodInfo.specType) this.watCh(val);
		//     },
		//     immediate: false,
		//     deep: true,
		//   },
		// },
		onLoad: function(options) {
			this.action = `${HTTP_REQUEST_URL}api/admin/upload/oss/image?model=content&pid=0`;
			this.headers = {
				[TOKENNAME]: this.token,
				["Identification"]: "APP",
			};
			if (!options.id) {
				uni.setNavigationBarTitle({
					title: this.$t("navigation.quickLaunch") //快速上架
				});
			} else {
				this.id = options.id;
				uni.setNavigationBarTitle({
					title: this.$t("navigation.selfBuiltProductDetails")
				});
			}
			this.getAllCategory(); // 获取分类列表
			this.getBrandList(); // 获取品牌列表
			this.getSeasonList(); // 获取季节列表
			this.getStockAreaList(); // 获取发货地列表
			// this.productGetRule(); // 获取商品属性模板
		},
		methods: {
			handleTap(name) {
				this.$refs[name].show();
			},
			// watCh(val) {
			//   const tmp = {};
			//   const tmpTab = {};
			//   this.goodInfo.attr.forEach((o, i) => {
			//     tmp["value" + i] = { title: o.attrName };
			//     tmpTab["value" + i] = "";
			//   });
			//   this.ManyAttrValue.push({
			//     image: "",
			//     price: 0,
			//     cost: 0,
			//     otPrice: 0,
			//     stock: 0,
			//     barCode: "",
			//     weight: 0,
			//     volume: 0,
			//     brokerage: 0,
			//     brokerage_two: 0,
			//   });
			// },
			handleConfirm(e) {
				console.info(e, "多规格");
				if (e.dataset.name == "stockAreaPicker") {
					this.$set(this.goodInfo, "tempName", this.$t(`publicLang.${e.item.label}`));
					this.$set(this.goodInfo, "tempId", e.value);
				}
				if (e.dataset.name == "selectRulePicker") {
					this.$set(this.goodInfo, "selectRuleName", e.item.label);
					this.$set(this.goodInfo, "selectRule", e.value);
					const data = [];
					let arr = [];
					e.item.ruleValue.forEach((item) => {
						data.push({
							attrName: item.value,
							attrValue: item.detail
						});
					});
					console.info(this.goodInfo.image ? 1 : 0, 123123)
					this.goodInfo.attr = data;
					data.map((m) => {
						m.attrValue.map((k) => {
							arr.push({
								attrValue: {
									[this.goodInfo.attr[0].attrName]: k
								},
								image: this.goodInfo.image ? this.goodInfo.image : "",
								imageurl: this.goodInfo.image ? [{
									url: this.goodInfo.image
								}] : "",
								price: 0,
								cost: 0,
								otPrice: 0,
								stock: 0,
								barCode: "",
								weight: "",
								volume: "",
								brokerage: "",
								brokerageTwo: "",
								manyTabDate: k,
							});
						});
					});

					this.ManyAttrValue = arr;
					console.info(this.ManyAttrValue)
					if (this.goodInfo.image) {
						this.OneattrValue[0].image = this.goodInfo.image
						this.batchImage = [{
							url: this.goodInfo.image
						}]
					}
				}
			},
			// 运费模板；
			getBrandList() {
				uni.showLoading({
					mask:true
				})
				brandList({
					type: 1,
				}).then((res) => {
					uni.hideLoading()
					this.brandList = res.data;
					this.brandDisabled = false
				});
			},
			// 获取发货地
			getStockAreaList() {
				var _this = this;
				stockAreaList().then((res) => {
					let list = [];
					res.data.map((i) => {
						list.push({
							label: _this.$t(`publicLang.${i.stockAreaName}`),
							value: i.tempId,
						});
					});
					_this.stockArea = list;
					if (this.id) {
						this.getGoodsDetail(); //获取自建商品详情
					}
				});
			},
			// 获取商品属性模板；
			productGetRule() {
				templateListApi(this.tableFrom).then((res) => {
					console.info(res.data.list);
					const list = res.data.list;
					let arr = [];
					list.map((i) => {
						arr.push({
							label: i.ruleName,
							value: i.id,
							ruleValue: JSON.parse(i.ruleValue),
						});
					});
					console.info(arr);
					this.ruleList = arr;
				});
			},
			dealPrice: function(val, val1) {
				return Number(val) + Number(val1);
			},
			// 分类列表
			getAllCategory: function() {
				let that = this;
				categoryApi({
					status: 1,
					type: 1,
				}).then((res) => {
					that.productList = res.data;
					this.getStockAreaList(); // 获取发货地列表
				});
			},

			uploadImg(res, type, index) {
				if (type == 0) {
					//商品主图
					this.goodInfo.image = res.data.url;
				} else if (type == 1) {
					//商品轮播图
					this.goodInfo.sliderImages.push(res.data.url);
				} else if (type == 2) {
					//商品推荐图
					this.goodInfo.recommendImg = res.data.url;
				} else if (type == 3) {
					//商品批量规格图
					this.OneattrValue[0].image = res.data.url;
				} else if (type == 4) {
					this.ManyAttrValue[index].image = res.data.url;
				} else if (type == 5) {
					console.info(res.data)
					this.goodInfo.detailImages.push(res.data.url);
				}
			},
			// 删除图片
			deletePic(index, type, index1) {
				if (type == 0) {
					//商品主图
					this.goodInfo.image = "";
				} else if (type == 1) {
					//商品轮播图
					// this.fileListsliderImage.splice(index,1)
					this.goodInfo.sliderImages.splice(index, 1);
				} else if (type == 2) {
					//商品规格图
					this.goodInfo.recommendImg = "";
				} else if (type == 3) {
					//商品批量规格图
					this.OneattrValue[0].image == "";
				} else if (type == 4) {
					this.ManyAttrValue[index1].image = "";
				} else if (type == 5) {
					this.goodInfo.detailImages.splice(index, 1);
				}
			},

			bindChange2(e) {
				let {
					value
				} = e.detail;
				console.log(value);
				if (value[0] != this.value2[0]) {
					this.value2 = [];
					this.value2.push(value[0]);
					this.value2.push(0);
					this.value2.push(0);
				}
				if (value[1] != this.value2[1]) {
					this.value2 = [];
					this.value2.push(value[0]);
					this.value2.push(value[1]);
					this.value2.push(0);
				} else {
					if (value[0] == this.value2[0] && value[1] == this.value2[1]) {
						this.value2 = [];
						this.value2.push(value[0]);
						this.value2.push(value[1]);
						this.value2.push(value[2]);
					}
				}
				this.index1 = e.detail.value[0];
				this.index2 = e.detail.value[1];
			},
			// 修改分类
			confirmTap() {
				let _this = this
				let {
					value1,
					value2,
					productList
				} = this.$data;
				if (productList[value2[0]].child) {
					if (productList[value2[0]]["child"][value2[1]]["child"]) {
						this.goodInfo.cateIds = productList[value2[0]]["child"][value2[1]]["child"][value2[2]]["id"];
						this.goodInfo.cateName =
							productList[value2[0]]["name"] + "/" +
							productList[value2[0]]["child"][value2[1]]["name"] + "/" +
							productList[value2[0]]["child"][value2[1]]["child"][value2[2]]["name"];
					} else {
						this.goodInfo.cateIds = productList[value2[0]]["child"][value2[1]]["id"];
						this.goodInfo.cateName = productList[value2[0]]["name"] + "/" + productList[value2[0]]["child"][
							value2[1]
						]["name"];
					}
				} else {
					this.goodInfo.cateIds = productList[value2[0]]["id"];
					this.goodInfo.cateName = productList[value2[0]]["name"]
				}
				this.getRuleByCate()
				this.showPicker = false;
			},
			getRuleByCate(info) {
				let _this = this
				_this.informationList = []
				getRuleByCate({
					cateId: this.goodInfo.cateIds
				}).then((res) => {
					console.info(res.data.informationList, info, 11)
					if (info) {
						let productInformation = JSON.parse(info)
						if (res.data.informationList) {
							_this.informationList = JSON.parse(JSON.stringify(res.data.informationList))
							_this.informationList.map(i => {
								i.value = ""
								productInformation.map(j => {
									if (i.productInformation == j.infoName) {
										i.value = j.infoValue
									}
								})
							})
						}
					} else {
						if (res.data.informationList) {
							_this.informationList = res.data.informationList
						}
						_this.informationList.map((i, index) => {
							i.value = ""
						})
					}
					const list = res.data.storeProductRuleList;
					let arr = [];
					list.map((i) => {
						arr.push({
							label: i.ruleName,
							value: i.id,
							ruleValue: JSON.parse(i.ruleValue),
						});
					});
					_this.ruleList = arr;

					const infoList = ["成分", "规格", "重量", "色号", "产地", "季节"]; //页面固有字段
					const infoField = {
						"成分": "composition",
						"规格": "dimension",
						"季节": "seasonCode",
						"色号": "colorCode",
						"产地": "productionPlace",
						"重量": "weight"
					} //页面固有字段对应显示字段
					_this.showField = {
						composition: false,
						dimension: false,
						seasonCode: false,
						colorCode: false,
						productionPlace: false,
						weight: false,
					} //固有字段初始设为隐藏
					for (var i = 0; i < _this.informationList.length; i++) {
						if (infoList.indexOf(_this.informationList[i].productInformation) != -1) { //匹配到的是否包含固有字段
							_this.showField[infoField[_this.informationList[i].productInformation]] =
							true; //显示页面字段   
							_this.informationList.splice(i, 1); //删除数组内的固有字段   
							i--; //i需要自减，否则每次删除都会讲原数组索引发生变化
						}
					}
					console.info(_this.showField,"_this.showField")
				});
			},
			// 品牌修改
			bindPickerBrand(e) {
				let {
					value
				} = e.detail;
				this.$set(this.goodInfo, "brandName", this.brandList[value].enName);
				this.$set(this.goodInfo, "brandId", this.brandList[value].id);
			},
			bindPickerSeason(e) {
				let {
					value
				} = e.detail;
				this.$set(this.goodInfo, "seasonCode", this.seasonList[value].name);
			},
			// 季节列表
			getSeasonList() {
				seasonListMer().then((res) => {
					this.seasonList = res.data;
				});
			},
			// 删除属性
			handleClose(item, index) {
				this.ManyAttrValue.splice(index, 1);
				item.splice(index, 1);
			},
			addAttr() {
				this.editState = true;
			},
			addAttrBlur(num, idx) {
				if (num) {
					this.goodInfo.attr[0].attrValue.push(num);
					this.ManyAttrValue.push({
						attrValue: {
							[this.goodInfo.attr[0].attrName]: num
						},
						image: this.goodInfo.image ? this.goodInfo.image : "",
						imageurl: this.goodInfo.image ? [{
							url: this.goodInfo.image
						}] : "",
						price: "",
						cost: "",
						otPrice: "",
						stock: "",
						barCode: "",
						weight: "",
						volume: "",
						brokerage: "",
						brokerageTwo: "",
						manyTabDate: num,
					});
				}
				this.editState = false;
			},
			// 批量添加
			batchAdd() {
				let count = 0
				for (const item of this.ManyAttrValue) {
					count = count + 1
					if (item.imageurl.length > 0) {
						this.$refs.upload4[count - 1].clear()
						item.imageurl = []
					}
					this.$nextTick(function() {
						if (this.OneattrValue[0].image && this.goodInfo.specType == 1) {
							console.info(item.imageurl)
							let filelist = [];
							let data = {};
							data.url = this.OneattrValue[0].image;
							filelist.push(data);
							this.$set(item, "imageurl", filelist);
						}
						this.$set(item, "image", this.OneattrValue[0].image);
						this.$set(item, "cost", this.OneattrValue.cost);
						this.$set(item, "price", this.OneattrValue.price);
						this.$set(item, "otPrice", this.OneattrValue.otPrice);
						this.$set(item, "stock", this.OneattrValue.stock);
						this.$set(item, "barCode", this.OneattrValue.barCode);
						this.$set(item, "weight", this.OneattrValue.weight);
						this.$set(item, "volume", this.OneattrValue.volume);
						this.$set(item, "brokerage", this.OneattrValue.brokerage);
						this.$set(item, "brokerageTwo", this.OneattrValue.brokerageTwo);
					})

				}
			},
			// 国际编码查询
			querySearchAsync() {
				if (this.goodInfo.keyword.length < 5) {
					this.keywordList = [];
					return;
				}
				productNormKeywordApi(this.goodInfo.keyword).then((res) => {
					this.keywordList = res.data;
				});
			},
			// 匹配商品信息
			bindPickerKeyword(e) {
				let {
					value
				} = e.detail;
				this.goodInfo.keyword = this.keywordList[value].keyword;
				this.querySearchAsync();
				let id = this.goodInfo.keyword;
				if (!id) {
					return that.$util.Tips({
						title: this.$t('publicLang.successfulOperation')
					});
				}
				if (this.fileListImg.length > 0) {
					this.$refs.upload.clear();
					this.fileListImg = [];
				}
				if (this.fileListsliderImage.length > 0) {
					this.$refs.upload1.clear();
					this.fileListsliderImage = [];
				}
				if (this.fileListproductDetails.length > 0) {
					this.$refs.upload5.clear();
					this.fileListproductDetails = [];
				}
				if (
					this.goodInfo.specType == 0 &&
					this.OneattrValue[0].imageurl.length > 0
				) {
					this.$refs.imageRef.clear();
					this.OneattrValue[0].imageurl = [];
				}
				productNormKeywordApi(id).then((res) => {
					let info = res.data[0];
					//处理详情图
					const detail = ["gwpp1", "gwmt1", "sp1", "sp", "mt1", "mt", "mx1", "api"];
					let detailArr = []
					let videoArr = [];
					detail.map((item) => {
						if (info[item]) {
							let arr = JSON.parse(info[item]);
							arr.map(re => {
								if (item == "sp2" || item == "sp3") {
									videoArr.push(re)
								} else {
									detailArr.push(re)
								}
							})
						}
					})
					if (detailArr.length == 0) detailArr = JSON.parse(info.sliderImage)
					if (videoArr.length > 0) info.videoLink = videoArr[0] //有数据赋值轮播图视频
					this.goodInfo.detailImages = detailArr;
					this.goodInfo.sp1 = JSON.stringify(detailArr),
						this.goodInfo.image = info.image;
					this.fileListImg.push({
						url: this.goodInfo.image
					});
					this.goodInfo.sliderImages = JSON.parse(info.sliderImage);
					this.goodInfo.sliderImages.map((item) => {
						this.fileListsliderImage.push({
							url: item
						});
					});
					this.goodInfo.detailImages.map((item) => {
						this.fileListproductDetails.push({
							url: item
						});
					});
					this.goodInfo.sliderImage = info.sliderImage;
					this.goodInfo.productionPlace = info.productionPlace;
					this.goodInfo.weight = info.weight;
					this.goodInfo.storeName = info.storeName;
					this.goodInfo.recommendImg = info.recommendImg;
					if (this.goodInfo.recommendImg) {
						this.fileListrecommendImg.push({
							url: this.goodInfo.recommendImg
						});
					}
					this.goodInfo.storeInfo = info.storeInfo;
					this.goodInfo.keyword = info.keyword;
					this.goodInfo.cateIds =
						info.cateId == null || info.cateId == "null" ?
						"" :
						Number(info.cateId);
					// this.formValidate.cateId = info.cateId
					if (this.goodInfo.cateIds) {
						this.getRuleByCate()
					}
					this.goodInfo.unitName = info.unitName;
					this.goodInfo.sort = info.sort;
					// this.goodInfo.isShow = info.isShow;
					this.goodInfo.isBenefit = info.isBenefit;
					this.goodInfo.isNew = info.isNew;
					this.goodInfo.isGood = info.isGood;
					this.goodInfo.isHot = info.isHot;
					this.goodInfo.isBest = info.isBest;
					this.goodInfo.tempId = info.tempId;
					this.brandList.map((item) => {
						if (item.id == info.brandId) {
							this.goodInfo.brandId = info.brandId;
							this.goodInfo.brandName = info.brandName;
						}
					});
					// this.goodInfo.brandName = info.brandName;
					// this.formValidate.attrValue = info.attrValue
					// this.formValidate.attr = info.attr || []
					this.goodInfo.selectRule = info.selectRule;
					this.goodInfo.isSub = info.isSub;
					this.goodInfo.content = " ";
					// this.formValidate.specType = info.specType || false
					// this.formValidate.id = info.id
					this.goodInfo.giveIntegral = info.giveIntegral;
					this.goodInfo.ficti = info.ficti;
					this.goodInfo.coupons = info.coupons;
					this.goodInfo.composition = info.composition;
					this.goodInfo.season = info.season;
					this.goodInfo.dimension = info.dimension;
					this.goodInfo.earliestArrivalData = info.earliestArrivalData;
					this.goodInfo.slowestArrivalData = info.slowestArrivalData;
					this.goodInfo.deliveryData = info.deliveryData;
					if (info.image) {
						let data = {};
						let filelist = [];
						data.url = info.image;
						filelist.push(data);
						this.OneattrValue[0].imageurl = filelist;
					}
					this.OneattrValue[0].image = info.image;
					try {
						a: for (let i of this.productList) {
							if (this.goodInfo.cateIds != i.id) {
								if (i.child) {
									b: for (let j of i.child) {
										if (this.goodInfo.cateIds != j.id) {
											if (j.child) {
												c: for (let k of j.child) {
													if (this.goodInfo.cateIds == k.id) {
														this.goodInfo.cateName = i.name + "/" + j
															.name + "/" + k.name
														break a;
													}
												}
											}
										} else {
											this.goodInfo.cateName = i.name + "/" + j.name
											break a;
										}
									}
								}
							} else {
								this.goodInfo.cateName = i.name
								break;
							}
						}
						// this.productList.map((item, idx) => {
						// 	item.child.map((iitem, idx1) => {
						// 		if (iitem.child) {
						// 			iitem.child.map((iiitem, idx2) => {
						// 				if (iiitem.id == this.goodInfo.cateIds) {
						// 					this.goodInfo.cateName =
						// 						item.name + "/" + iitem.name + "/" + iiitem
						// 						.name;
						// 				}
						// 			});
						// 		}
						// 	});
						// });
					}
					catch (e) {
						console.info(e)
					}

				});
			},
			// 商品详情
			getGoodsDetail() {
				uni.showLoading({
					title: this.$t("publicLang.loading")
				});
				insideProductDetailApi(this.id).then((res) => {
					let info = res.data;
					let attr = [];
					let attr2 = {};
					if (info.attrValue.length > 0 && info.attrValue[0].attrValue) {
						//获取规格名
						info.attrValue.map(re => {
							attr = Object.keys(JSON.parse(re.attrValue))
						})
						attr.map(rr => {
							attr2[rr] = []
						})
						//获取规格值
						info.attrValue.map(re => {
							let a = JSON.parse(re.attrValue)
							attr.map(rr => {
								if (!attr2[rr].includes(a[rr])) {
									attr2[rr].push(a[rr])
								}
							})
						})
						//生成attr
						let attrVal = [];
						attr.map(rr => {
							let arr = {}
							arr.attrName = rr
							arr.attrValues = attr2[rr].join(",")
							attrVal.push(arr)
						})
						info.attr = attrVal;
					}

					//处理单规格或多规格
					if (info.attr.length == 1 && (info.attr[0].attrName == "尺寸" || info.attr[0].attrName ==
							"规格") &&
						info.attr[0].attrValues == "默认" && info.attrValue.length == 1) {
						info.specType = false
					} else {
						info.specType = true
					}
					//处理详情图
					const detail = ["gwpp1", "gwmt1", "sp1", "sp", "mt1", "mt", "mx1", "api"];
					let detailArr = []
					let videoArr = [];
					detail.map((item) => {
						if (info[item]) {
							let arr = JSON.parse(info[item]);
							arr.map(re => {
								if (item == "sp2" || item == "sp3") {
									videoArr.push(re)
								} else {
									detailArr.push(re)
								}
							})
						}
					})
					if (detailArr.length == 0) detailArr = JSON.parse(info.sliderImage)
					if (videoArr.length > 0) info.videoLink = videoArr[0] //有数据赋值轮播图视频
					this.goodInfo = {
						image: info.image,
						recommendImg: info.recommendImg,
						sliderImages: JSON.parse(info.sliderImage),
						sliderImage: info.sliderImage,
						detailImages: detailArr,
						sp1: JSON.stringify(detailArr),
						storeName: info.storeName,
						storeInfo: info.storeInfo,
						seasonCode: info.seasonCode,
						colorCode: info.colorCode,
						keyword: info.keyword,
						cateIds: info.cateId == null || info.cateId == "null" ?
							"" : Number(info.cateId), // 商品分类id
						cateId: info.cateId, // 商品分类id传值
						unitName: info.unitName,
						sort: info.sort,
						isShow: info.isShow,
						isBenefit: info.isBenefit,
						isNew: info.isNew,
						isGood: info.isGood,
						isHot: info.isHot,
						isBest: info.isBest,
						tempId: info.tempId,
						brandId: info.brandId,
						brandName: info.brandName,
						// barCode: info.barCode,
						deliveryData: info.deliveryData,
						attrValue: info.attrValue,
						attr: info.attr,
						selectRule: info.selectRule,
						isSub: info.isSub,
						content: " ",
						specType: info.specType ? 1 : 0,
						id: info.id,
						giveIntegral: info.giveIntegral,
						ficti: info.ficti,
						coupons: info.coupons,
						composition: info.composition,
						dimension: info.dimension,
						deliveryData: info.deliveryData,
						earliestArrivalData: info.earliestArrivalData,
						slowestArrivalData: info.slowestArrivalData,
						videoLink: info.videoLink,
						secondhand: info.degree ? true : false,
						degree: info.degree,
						productionPlace: info.productionPlace,
						weight: info.weight,
					};
					this.informationList = []
					if (this.goodInfo.cateIds && info.productInformation) {
						this.getRuleByCate(info.productInformation)
					}
					this.fileListImg.push({
						url: this.goodInfo.image
					});
					this.goodInfo.detailImages.map((item) => {
						this.fileListproductDetails.push({
							url: item
						});
					});
					this.goodInfo.sliderImages.map((item) => {
						this.fileListsliderImage.push({
							url: item
						});
					});
					if (this.goodInfo.recommendImg) {
						this.fileListrecommendImg.push({
							url: this.goodInfo.recommendImg
						});
					}
					a: for (let i of this.productList) {
						if (this.goodInfo.cateIds != i.id) {
							if (i.child) {
								b: for (let j of i.child) {
									if (this.goodInfo.cateIds != j.id) {
										if (j.child) {
											c: for (let k of j.child) {
												if (this.goodInfo.cateIds == k.id) {
													this.goodInfo.cateName = i.name + "/" + j.name +
														"/" + k.name
													break a;
												}
											}
										}
									} else {
										this.goodInfo.cateName = i.name + "/" + j.name
										break a;
									}
								}
							}
						} else {
							this.goodInfo.cateName = i.name
							break;
						}
					}
					// this.productList.map((item, idx) => {
					// 	if (item.child) {
					// 		item.child.map((iitem, idx1) => {
					// 			if (iitem.child) {
					// 				iitem.child.map((iiitem, idx2) => {
					// 					if (iiitem.id == this.goodInfo.cateIds) {
					// 						this.goodInfo.cateName =
					// 							item.name + "/" + iitem.name + "/" + iiitem
					// 							.name;
					// 					}
					// 				});
					// 			}
					// 		});
					// 	}

					// });

					this.stockArea.map((item, index) => {
						if (item.value == info.tempId) {
							this.goodInfo.tempName = item.label;
						}
					});
					if (info.specType) {
						this.goodInfo.attr = info.attr.map((item) => {
							return {
								attrName: item.attrName,
								attrValue: item.attrValues.split(","),
							};
						});
						info.attrValue.map((i, index) => {
							let valueArr = i.suk.split(",");
							this.goodInfo.attr.map((j, jndex) => {
								i.manyTabDate = valueArr[jndex];
							});
						});
						this.ManyAttrValue = info.attrValue;
						// this.ManyAttrValue.forEach((val) => {
						// this.attrInfo[Object.values(val.attrValue).sort().join("/")] = val;
						// });
						this.ManyAttrValue.map((item) => {
							item.attrValue = JSON.parse(item.attrValue);
							if (item.image) {
								let filelist = [];
								let data = {};
								data.url = item.image;
								filelist.push(data);
								item.imageurl = filelist;
							}
						});
						this.OneattrValue[0].image = this.goodInfo.image;
					} else {
						this.OneattrValue = info.attrValue;
						this.OneattrValue.map((item) => {
							if (item.image) {
								let filelist = [];
								let data = {};
								data.url = item.image;
								filelist.push(data);
								item.imageurl = filelist;
							}
						});
						this.goodInfo.attr = [];
					}
					console.info(this.fileListrecommendImg);
					uni.hideLoading();
				});
			},
			// // 清空加价方式
			// resetPrice(id){
			//   var that = this;
			//   productResetPrice({productId:id}).then((res)=>{
			//     that.$util.Tips({title:'操作成功'},{tab:4,url:'/pages/goods_management/index'})
			//   })
			// }
			// 提交
			handleSubmit() {
				console.log(this.goodInfo);
				uni.showLoading({
					title: this.$t("publicLang.loading")
				});
				var that = this;
				if (!this.goodInfo.keyword)
					return that.$util.Tips({
						title: this.$t("goods.pleaseEnterTheProductInternationalCode") // 请输入商品国际编码
					});
				if (!this.goodInfo.storeName)
					return that.$util.Tips({
						title: this.$t("goods.pleaseEnterProductName") // 请输入商品名称
					});
				if (!this.goodInfo.unitName)
					return that.$util.Tips({
						title: this.$t("goods.pleaseEnterProductUnit")
					});
				if (!this.goodInfo.brandName)
					return that.$util.Tips({
						title: this.$t("goods.pleaseSelectProductBrand")
					});
				if (!this.goodInfo.cateName)
					return that.$util.Tips({
						title: this.$t("goods.pleaseSelectProductCategory")
					});
				if (!this.goodInfo.image)
					return that.$util.Tips({
						title: this.$t("goods.pleaseSelectTheMainImageOfTheProduct")
					});
				if (this.goodInfo.sliderImages.length < 1)
					return that.$util.Tips({
						title: this.$t("goods.pleaseSelectProductCarousel")
					});
				if (!this.goodInfo.tempName)
					return that.$util.Tips({
						title: this.$t("goods.pleaseSelectTheShippingLocation")
					});
				if (!this.goodInfo.deliveryData)
					return that.$util.Tips({
						title: this.$t("goods.pleaseEnterDeliveryTime")
					});
				if (!this.goodInfo.earliestArrivalData || !this.goodInfo.slowestArrivalData)
					return that.$util.Tips({
						title: this.$t("goods.pleaseEnterTheArrivalTime")
					});
				if (this.goodInfo.specType == 1 && this.goodInfo.attr.length < 1)
					return that.$util.Tips({
						title: `${this.$t("goods.pleaseFillInTheMultiSpecificationAttributes")}！`
					});
				if (this.goodInfo.secondHand && this.goodInfo.degree == "") {
					return that.$util.Tips({
						title: `${this.$t("goods.pleaseEnterTheDegreeOfOldOrNew")}！`
					});
				}
				if (this.goodInfo.specType == 1) {
					for (var j = 0; j < that.ManyAttrValue.length; j++) {
						// if (that.ManyAttrValue[j].stock == "0") {
						// 	return that.$util.Tips({
						// 		title: "商品库存不能为0哦~"
						// 	});
						// }
						that.ManyAttrValue[j].price = that.ManyAttrValue[j].price == "" ? 0 : that.ManyAttrValue[j].price;
						that.ManyAttrValue[j].cost = that.ManyAttrValue[j].cost == "" ? 0 : that.ManyAttrValue[j].cost;
						that.ManyAttrValue[j].otPrice = that.ManyAttrValue[j].otPrice == "" ? 0 : that.ManyAttrValue[j]
							.otPrice;
					}
					console.info(that.ManyAttrValue, 'ManyAttrValue')
					this.goodInfo.attrValue = that.ManyAttrValue;
					for (var i = 0; i < this.goodInfo.attr.length; i++) {
						this.goodInfo.attr[i].attrValues = this.goodInfo.attr[i].attrValue.join(",");
					}
				} else {
					this.goodInfo.attr = [];
					// if (this.OneattrValue[0].stock == "0") {
					// 	return that.$util.Tips({
					// 		title: "商品库存不能为0哦~"
					// 	});
					// }

					this.OneattrValue[0].price = this.OneattrValue[0].price == "" ? 0 : this.OneattrValue[0].price;
					this.OneattrValue[0].cost = this.OneattrValue[0].cost == "" ? 0 : this.OneattrValue[0].cost;
					this.OneattrValue[0].otPrice = this.OneattrValue[0].otPrice == "" ? 0 : this.OneattrValue[0].otPrice
					console.info(this.OneattrValue, 'OneattrValue')
					this.goodInfo.attrValue = this.OneattrValue;
					for (var i = 0; i < this.goodInfo.attrValue.length; i++) {
						if (this.goodInfo.attrValue[i].attrValue && typeof this.goodInfo.attrValue[i].attrValue !=
							"object") {
							this.goodInfo.attrValue[i].attrValue =
								JSON.parse(this.goodInfo.attrValue[i].attrValue)
						}
					}
				}
				this.goodInfo.specType = this.goodInfo.specType == 1 ? true : false;
				this.goodInfo.sliderImage = JSON.stringify(this.goodInfo.sliderImages);
				if (this.goodInfo.cateIds) {
					this.goodInfo.cateId = String(this.goodInfo.cateIds);
					this.goodInfo.cateIds = [this.goodInfo.cateId];
				}
				this.goodInfo.sp1 = JSON.stringify(
					this.goodInfo.detailImages
				);
				let productInformationArr = []
				this.informationList.map((i, index) => {
					productInformationArr.push({
						infoName: i.productInformation,
						infoValue: i.value
					})
				})
				this.$set(this.goodInfo, 'productInformation', JSON.stringify(productInformationArr))
				let flag = true;
				for (let val of this.goodInfo.attrValue) {
					if (val.stock == 0) {
						flag = false;
						break;
					}
				}
				if (flag) {
					this.product()
				} else {
					uni.hideLoading()
					uni.showModal({
						title: this.$t('publicLang.hint'),
						content: this.$t('goods.specificationTips'),
						confirmText: this.$t('publicLang.sure'),
						cancelText: this.$t('publicLang.cancel'),
						success: function(res) {
							if (res.confirm) {
								uni.showLoading({
									title: that.$t("publicLang.loading")
								});
								that.product()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			product() {
				var that = this;
				this.id ?
					productUpdateApi(this.goodInfo)
					.then((res) => {
						uni.hideLoading();
						that.$util.Tips({
							title: that.$t("goods.successfullyModified")
						}, {
							tab: 5,
							url: "/pages/goods_management/index?id=1"
						});
					})
					.catch((err) => {
						that.$util.Tips({
							title: err
						});
					}) :
					productCreateApi(this.goodInfo)
					.then((res) => {
						uni.hideLoading();
						that.$util.Tips({
							title: that.$t("goods.addedSuccessfully")
						}, {
							tab: 5,
							url: "/pages/goods_management/index?id=1"
						});
					})
					.catch((err) => {
						that.$util.Tips({
							title: err
						});
					});
			},
			getVideoUrl(e) {
				console.info(e);
				this.goodInfo.videoLink = e
			},
			changeType(val) {
				var _this = this
				if (_this.id) return
				uni.showModal({
					title: this.$t("publicLang.hint"),
					content: this.$t("goods.operationTips"),
					confirmText: this.$t("publicLang.sure"),
					cancelText: this.$t("publicLang.cancel"),
					success: function(res) {
						if (res.confirm) {
							_this.goodInfo = Object.assign({}, defaultObj);
							if (_this.keywordList.length > 0) {
								_this.keywordList = [];
							}
							if (_this.fileListImg.length > 0) {
								_this.$refs.upload.clear();
								_this.fileListImg = [];
							}
							if (_this.fileListsliderImage.length > 0) {
								_this.$refs.upload1.clear();
								_this.fileListsliderImage = [];
							}
							if (_this.fileListproductDetails.length > 0) {
								_this.$refs.upload5.clear();
								_this.fileListproductDetails = [];
							}
							if (_this.fileListrecommendImg.length > 0) {
								_this.$refs.upload2.clear();
								_this.fileListrecommendImg = [];
							}
							if (_this.goodInfo.specType != 1) {
								_this.OneattrValue = Object.assign({}, defaultObj.attrValue[0])
							} else {
								_this.ManyAttrValue = Object.assign({}, defaultObj.attrValue[0])
							}
							_this.goodInfo.secondhand = val;
						}
					}
				});
			},
			// 校验输入框
			check_input(e) {
				// console.info(e.currentTarget.dataset.eventOpts[0][1][0][1][1])
				let name = e.currentTarget.dataset.eventOpts[0][1][0][1][1]
				let value = e.detail.value
				var regRule =
					/[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig;;
				if (regRule.test(value)) {
					e.detail.value = value.replace(regRule, '')
					this.$nextTick(() => {
						this.goodInfo[name] = e.detail.value
						this.$util.Tips({
							title: this.$t("goods.notUseEmoji") // 请勿使用表情符号
						});
					})
				}
				var regStr2 = /[`~!@#$%^&*()+=|{}\[\]<>/~]/;
				if (regStr2.test(value)) {
					e.detail.value = value.replace(regStr2, '')
					this.$nextTick(() => {
						this.goodInfo[name] = e.detail.value
						this.$util.Tips({
							title: this.$t("goods.specialCharactersCannotBeEntered") // 不能输入特殊字符
						});
					})
				}
			}


		},
	};
</script>
<style lang="scss" scoped>
	.goods-detail {
		background: #ffffff;
		padding: 10rpx 18rpx;

		.uni-form-item {
			padding: 20rpx 30rpx;

			.title {
				padding: 10rpx 0rpx;
				margin-bottom: 10px;
				font-weight: bold;

				.required {
					color: #ff0000;
				}
			}

			.tabs {
				padding: 6rpx;

				.tabs_item {
					flex: 1;
					border-radius: 8rpx;
					padding: 10rpx;
					text-align: center;
				}

				.active {
					background: white;
					font-size: 26rpx;
					font-weight: 600;
				}
			}

			.select {
				display: flex;
				background: #f2f2f2;
				justify-content: space-between;
				align-items: center;

				.iconfont {
					margin-right: 10rpx;
					color: #999999;
					font-size: 24rpx;
				}

				.keyBtn {
					width: 90rpx;
					background: black;
					margin-right: 17rpx;
					text-align: center;
					color: white;
				}
			}

			.uni-input {
				padding: 15rpx 25rpx;
				background: #f2f2f2;
			}

			.imageBox {
				.image {
					width: 80rpx;
					height: 80rpx;
					margin: 0rpx 5rpx;
				}
			}

			.text {
				border: 1rpx solid #e8e9ed;
				width: 100%;
				height: 200rpx;
			}

			.goodsInfo {
				// border-top: 1rpx solid #e8e9ed;
				margin: 40rpx 0rpx;

				.item-list {
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.item {
						display: flex;
						align-items: center;
						padding: 20rpx 10rpx;
						width: 326rpx;
						flex-shrink: 0;
						border-bottom: 1rpx solid #e8e9ed;
						border-left: 1rpx solid #E8E9ED;

						.title1 {
							width: 138rpx;
							margin: 0rpx 7rpx;
							font-weight: bold;
							overflow: hidden;
							white-space: nowrap;
						}

						.btn {
							padding: 20rpx 35rpx;
							border-radius: 0;
							background: black;
							color: white;
							font-size: 24rpx;
							margin-left: 30rpx;
						}

						input,
						.picker {
							flex: 1;
						}
					}

					.item:nth-child(2n+1) {
						border-left: none
					}
				}
			}

			.goodsInfo1 {
				// border-top: 1rpx solid #e8e9ed;
				margin: 40rpx 0rpx;

				.item-list {
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					border-bottom: 1rpx solid #e8e9ed;

					.item {
						display: flex;
						align-items: center;
						padding: 20rpx 10rpx;
						width: 326rpx;

						.title1 {
							width: 138rpx;
							margin: 0rpx 7rpx;
							font-weight: bold;
						}

						.btn {
							padding: 20rpx 35rpx;
							border-radius: 0;
							background: black;
							color: white;
							font-size: 24rpx;
							margin-left: 30rpx;
						}

						input,
						.picker {
							flex: 1;
						}
					}
				}
			}

			.time {
				background: #f2f2f2;
				display: flex;
				align-items: center;
				padding: 10rpx 14rpx;

				input {
					padding: 5rpx 15rpx;
				}
			}

			.clearPrice {
				display: flex;
				align-items: center;

				.btn {
					padding: 20rpx 35rpx;
					border-radius: 0;
					background: black;
					color: white;
					font-size: 24rpx;
					margin-left: 30rpx;
				}
			}

			.alt {
				padding: 10rpx 0rpx;

				span {
					display: block;
					color: #bbbbbb;
					font-size: 22rpx;
				}
			}
		}

		.back_mask {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			top: 0;
			background-color: rgba(0, 0, 0, 0.5);
			z-index: 999;
		}

		// 新增样式start===============
		input {
			color: rgba(34, 34, 34, 1) !important;
		}

		.picker_address_box {
			left: 0;
			right: 0;
			height: 500rpx;
			background-color: #ffffff;
			position: absolute;
			bottom: 0;
			padding: 0 20rpx;

			.picker_btn {
				padding: 20rpx 0;
				font-size: 24rpx;
				color: #222222;
				display: flex;
				justify-content: space-between;

				.btn_confirm {
					background-color: rgba(34, 34, 34, 1);
					border-radius: 4rpx;
					color: #ffffff;
					padding: 10rpx 20rpx;
				}
			}

			.picker_box {
				height: 200rpx;
				position: absolute;
				width: 100%;
				bottom: 200rpx;

				.picker_view {
					height: 200rpx;
					font-size: 32rpx;
					text-align: center;
				}

				.area_type {
					width: 230rpx;
					text-align: center;
					flex: none;
				}

				.area_city {
					width: 230rpx;
					text-align: center;
					flex: none;
				}
			}
		}

		.footer {
			position: fixed;
			padding: 0rpx 20rpx;
			bottom: 0rpx;
			width: 100%;
			box-sizing: border-box;
			justify-content: space-between;
			align-items: center;
			display: flex;
			height: 150rpx;
			background-color: #fff;
			z-index: 277;
			border-top: 1rpx solid #f0f0f0;
			font-size: 24rpx;

			.btn {
				padding: 20rpx 315rpx;
				border: 1rpx solid #1d1c1c;
				background: black;
				color: #fff;
			}
		}
	}

	.slot-btn {
		width: 112rpx;
		height: 112rpx;
		padding: 30rpx;
		border: 1rpx solid #c7c7cc;
	}

	.imageBox ::v-deep .u-delete-icon {
		width: 30rpx;
		height: 30rpx;
		top: -11rpx;
		right: -6rpx;
	}

	.imageBox ::v-deep .u-list-item {
		overflow: inherit !important;
	}

	.selectRuleList {
		display: flex;
		flex-wrap: wrap;

		.selectRuleItem {
			border: 2rpx solid #e0e0e0;
			// width: 120rpx;
			padding: 0rpx 20rpx;
			height: 62rpx;
			text-align: center;
			font-size: 26rpx;
			line-height: 62rpx;
			margin: 6rpx;

			.icon {
				margin-left: 15rpx;
			}
		}

		// .selectRuleItem ~ .selectRuleItem {
		//   margin-left: 20rpx;
		// }
		.selectRuleAddItem {
			margin-left: 20rpx;
			border: 2rpx solid #e0e0e0;
			width: 126rpx;
			height: 62rpx;
			text-align: center;
			font-size: 26rpx;
			line-height: 62rpx;
			margin: 6rpx;
		}
	}
</style>
